﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FindAllHospital.aspx.cs" Inherits="HZ.Supervise.Web.Common.FindAllHospital" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>选择医院</title>
    <link rel="stylesheet" type="text/css" href="../style/global.css" />
    
    <script type="text/javascript" src="../scripts/jquery.js"></script>
    <script type="text/javascript" src="../scripts/mainlistSelect.js"></script>
    <script type="text/javascript" src="../scripts/Common.js"></script>
    <script type="text/javascript" src="../scripts/global.js"></script>

    <script type="text/javascript" language="javascript">
        function addHosInfo() {
            var hosInfo;
            hosInfo = document.getElementById("HosName").value +"|" + document.getElementById("HosId").value;
            window.parent.insertHosInfo(hosInfo);
            window.parent.hidePopWin(false);
        }

        function chkAllCompany() {
            CheckBoxList = document.getElementsByName("chkHos");
            for (var i = 0; i < CheckBoxList.length; i++) {
                CheckBoxList[i].checked = true;
            }
        }


        function insertCompanyInfo() {
            
            if (!checkSelectedItems('gvwHosList', '请至少选择一项！')) {
                return false;
            }
           
            CheckBoxList = document.getElementsByName("chkHos");
            var resultValue = "";
            var hosNames="";
            var hosIDs="";
            for (var i = 0; i < CheckBoxList.length; i++) {
                if (CheckBoxList[i].checked) {
                    resultValue = CheckBoxList[i].value;
                    tempId = resultValue.split("|")[0];
                    tempName = resultValue.split("|")[1];

                    hosIDs = hosIDs + tempId + ",";
                    hosNames = hosNames + tempName + ",";
                }
            }

            var listbox = document.getElementById("ListHos");
            var hosID = document.getElementById("HosId");
            var hosName = document.getElementById("HosName");
            var arrayName = hosNames.split(',');
            var arrayID = hosIDs.split(',');
            var isUnique = true;
            var temp;
            for (m = 0; m < arrayID.length; m++) {
                for (n = 0; n < listbox.options.length; n++) {
                    if (arrayID[m] == listbox.options[n].value) {
                        isUnique = false;
                        temp = arrayName[m];
                        break;
                    }
                }
            }

            if (isUnique == true) {
                for (var i = 0; i < arrayName.length; i++) {
                    if (!isNull(arrayName[i])) {
                        var listItem = document.createElement("OPTION");
                        listItem.text = arrayName[i];
                        listItem.value = arrayID[i];
                        listbox.add(listItem);
                    }
                }
            }
            else {
                alert("医院" + temp + "已经存在！");
                return;
            }

            hosID.value = "";
            hosName.value = "";
            for (j = listbox.options.length - 1; j >= 0; j--) {
                hosID.value = hosID.value + listbox[j].value + ",";
                hosName.value = hosName.value + listbox[j].text + ",";
            }
        }

        function deleteCompany() {
            if (!isNull(checkSelected())) {
                var info = checkSelected();
                alert(info);
                return;
            }
            var listbox = document.getElementById("ListHos");
            var companyID = document.getElementById("HosId");
            var companyName = document.getElementById("HosName");
            companyID.value = "";
            companyName.value = "";

            var selectindex = listbox.selectedIndex;
            listbox.remove(selectindex);

            for (j = listbox.options.length - 1; j >= 0; j--) {
                companyID.value = companyID.value + listbox[j].value + ",";
                companyName.value = companyName.value + listbox[j].text + ",";
            }
        }

        function checkSelected() {
            var info;
            var listbox = document.getElementById("ListHos");
            var selectindex = listbox.selectedIndex;
            if (selectindex < 0) {
                info = "请选择要删除的医院！";
                return info;
            }
            return "";
        }

        function isNull(str) {
            var re = /^[ \s]*$/;
            return re.test(str);
        }
    </script>


</head>
<body>
    <form id="form1" runat="server">
    <div class="listsearch">
        <table class="querylist">
            <tr>
                <td style="width: 60px">
                    <asp:Label ID="lblQueryCondition" runat="server" Text="医院名称："></asp:Label>
                </td>
                <td align="left">
                    <asp:TextBox ID="txtHosName" runat="server"></asp:TextBox>
                </td>
                <td style="width: 60px">
                    <hz:HzButton ID="btnQery" runat="server" Text="查询" CssClass="btn"
                        Width="50px" onclick="btnQery_Click" />
                </td>
            </tr>
            
        </table>
    </div>
    
 <table class="querylist">
<tr><td width="40%">选择医院：</td><td width="20%">&nbsp;</td><td width="40%">对比医院：</td></tr>
<tr><td> 
            <asp:GridView ID="gvwHosList" runat="server" CssClass="mainlist" 
                AutoGenerateColumns="False" DataKeyNames="HospitalID" 
                EmptyDataText="暂无符合条件的数据！">
            <Columns>
                <asp:TemplateField>
                        <HeaderTemplate>
                            <input id="chkAllHos" name="chkAllHos" type="checkbox" onclick="SelectAllCheckboxes(this,'gvwHosList','chkAllHos');" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <input id="chkHos" name="chkHos" type="checkbox" onclick="chkChecked(this,'gvwHosList','chkAllHos');"
                                value='<%# Eval("HospitalID") %>|<%# Eval("HospitalName") %>'> </input>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="医院名称">
                        <ItemTemplate>
                            <asp:Label ID="lblCoHosName" runat="server" Text='<%# Eval("HospitalName") %>'></asp:Label>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
            </Columns>
        </asp:GridView>
            
            <webdiyer:AspNetPager ID="AspNetPager1" runat="server"  NumericButtonCount="5"    CustomInfoStyle="display:none"
                onpagechanged="AspNetPager1_PageChanged" ShowFirstLast="False">
            </webdiyer:AspNetPager>
            
            </td>
            <td>
                <p><input type="button" id="btnIn" value="加入对比" class="btn" onclick="insertCompanyInfo();" /></p><p><input type="button" id="btnOut"  value="删除对比" class="btn" onclick="deleteCompany();" /></p><p><input type="button" id="btnOk" value="确认对比" class="btn" onclick="return addHosInfo();" /></p>
                </td>
                <td rowspan="2">
                <input id="HosId" type="hidden" name="HosId" runat="server" />
    <asp:ListBox ID="ListHos" runat="server" Height="300px" Width="100%">
       
    </asp:ListBox>
    <input id="HosName" type="hidden" name="HosName" runat="server" />
    </td>
    </tr>
        <tr><td>
            &nbsp;</td><td></td></tr>
</table>
 </form>
</body>
</html>
